export default {
    data() {
        return {
            steamer_id: 0,
            bath_room_list: [],
            imgList: [], //图片列表
            postData: {}, //七牛云postData
            descImageUrl: '', //图片
            desc_img: false, //是否展示删除
            domain: '', //图片域名
            ruleForm: {
                name: '',
                content: '',
                sn: '',
                radio: '1',
            },
            rules: {
                name: [{
                    required: true,
                    message: '请输入游轮名称',
                    trigger: 'blur'
                }, ],
                content: [{
                    required: true,
                    message: '请输入游轮介绍',
                    trigger: 'blur'
                }, ],
                sn: [{
                    required: true,
                    message: '请输入游轮编号',
                    trigger: 'blur'
                }, ],
            },

            //仓位验证
            add_berth_form: {
                berth_name: '',
            },
            add_berth_rules: {
                berth_name: [{
                    required: true,
                    message: '请输入仓位名称',
                    trigger: 'blur'
                }, ],
            },

            beth_index: '', //仓位下标

            // 添加房间 表单
            add_room_form: {
                name: '',
                size: '',
                people_num: '',
                floor_num: '',
                room_count: '',
                imgs: '',
            },
            // 添加房间 验证
            add_room_rules: {
                name: [{
                    required: true,
                    message: '请输入房间名称',
                    trigger: 'blur'
                }, ],
                size: [{
                    required: true,
                    message: '请输入房间面积',
                    trigger: 'blur'
                }, ],
                people_num: [{
                    required: true,
                    message: '请输入房间入住人数',
                    trigger: 'blur'
                }, ],
                floor_num: [{
                    required: true,
                    message: '请输入房间楼层',
                    trigger: 'blur'
                }, ],
                room_count: [{
                    required: true,
                    message: '请输入房间数量',
                    trigger: 'blur'
                }, ],
            },

            pictureList: [], //图片列表
            pictureUrl: '', //图片
            desc_picture: false, //是否展示删除
            is_audit:3,
            picture:''
        }
    },

    /**
     * 进入页面加载
     */
    mounted: function () {
        var that = this;
        //在缓存中获取值
        that.user_name = sessionStorage.getItem("user_name");
        that.user_id = sessionStorage.getItem("user_id");
        that.token = sessionStorage.getItem("access-token");
        if ((!that.token) || (!that.user_id) || (!that.user_name)) {
            that.$router.push('/login');
        }

        if (that.$route.query.steamer_id) {
            that.steamer_id = that.$route.query.steamer_id;
            that.detail();
        }
        that.getQiNiuToken();
    },

    /**
     * 方法
     */
    methods: {

        /**
         * 获取七牛云token
         */
        getQiNiuToken: function () {
            let that = this;
            //请求登陆接口
            that.$http.post(that.adminApi.api_url + "/Qiniu/getToken", {
                token: that.token,
            }, {
                emulateJSON: true
            }).then(
                function (res) {
                    // 处理成功的结果
                    that.postData = {
                        token: res.body.upToken,
                    }
                    that.domain = res.body.domain;
                },
                function () {
                    // 处理失败的结果
                    that.$message({
                        type: 'error',
                        message: `操作提示: ${ '处理异常' }`
                    });
                });
        },


        /**
         * 上传图片
         * @param file
         * @param fileList
         */
        //删除
        descRemove(file, fileList) {
            let that = this;
            that.imgList = fileList;
        },
        descPictureCardPreview(file) {
            this.descImageUrl = file.url;
            this.desc_img = true;
        },
        descError(res) { //显示错误
            console.log(res)
        },
        descAvatarSuccess(res, file) { //上传成功后在图片框显示图片
            let that = this;
            let imageUrl = {
                url: that.domain + res.key,
                uid: file['raw']['uid']
            };
            that.imgList.push(imageUrl);
        },
        //文件超出个数限制时的钩子
        descExceed(files, fileList) {
            this.$message.error('只能上传一张图片');
        },



        /**
         * 上传轮船图
         * @param file
         * @param fileList
         */
        //删除
        pictureRemove(file, fileList) {
            let that = this;
            that.pictureList = fileList;
        },
        picturePreview(file) {
            this.pictureUrl = file.url;
            this.desc_picture = true;
        },
        pictureError(res) { //显示错误
            console.log(res)
        },
        pictureSuccess(res, file) { //上传成功后在图片框显示图片
            let that = this;
            let imageUrl = {
                url: that.domain + res.key,
                uid: file['raw']['uid']
            };
            that.pictureList.push(imageUrl);
        },
        //文件超出个数限制时的钩子
        pictureExceed(files, fileList) {
            this.$message.error('只能上传一张图片');
        },

        /**
         *详情
         */
        detail: function () {
            var that = this;
            //请求的数据
            var formData = {};
            formData.token = that.token;
            formData.steamer_id = that.steamer_id;
            formData.seller_id = that.user_id;

            //请求邀请者列表
            that.$http.post(that.adminApi.api_url + "/steamer/showDetail", formData, {
                emulateJSON: true
            }).then(
                function (res) {
                    that.ruleForm.name = res.body.name;
                    that.ruleForm.subtitle = res.body.subtitle;
                    that.ruleForm.sn = res.body.sn;
                    that.ruleForm.radio = res.body.status.toString();
                    that.ruleForm.content = res.body.content;
                    that.is_audit = res.body.is_audit;
                    that.picture = res.body.picture;
                    if (res.body.steamer_berth.length !== 0) {
                        for (var i in res.body.steamer_berth) {
                            that.bath_room_list.push({
                                berth_id: res.body.steamer_berth[i].berth_id,
                                berth_name: res.body.steamer_berth[i].name,
                                image: res.body.steamer_berth[i].picture,
                                price_table: res.body.steamer_berth[i].steamer_room
                            })
                        }
                    }
                    // that.bath_room_list = res.body.steamer_berth;
                },
                function () {
                    // 处理失败的结果
                    that.$message({
                        type: 'error',
                        message: `操作提示: ${ '处理异常' }`
                    });
                });
        },
        /**
         * 返回
         */
        back() {
            this.$router.go(-1);
        },

        /**
         * 审核通过
         */
        pass:function (e) {
            const that = this;
            that.$confirm('确定通过审核吗?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                //请求的数据
                var formData = {};
                formData.token = that.token;
                formData.steamer_id = that.steamer_id;
                formData.is_audit = e;
                //请求邀请者列表
                that.$http.post(that.adminApi.api_url + "/steamer/audit", formData, {
                    emulateJSON: true
                }).then(
                    function (res) {
                        that.$message({
                            type: 'error',
                            message: `操作提示: ${ '审核成功' }`
                        });
                        that.$router.go(-1);
                    },
                    function () {
                        // 处理失败的结果
                        that.$message({
                            type: 'error',
                            message: `操作提示: ${ '处理异常' }`
                        });
                    });
            })
        },

        /**
         * 审核通过
         */
        no_pass:function (e) {
            const that = this;
            that.$confirm('确定驳回吗?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                //请求的数据
                var formData = {};
                formData.token = that.token;
                formData.steamer_id = that.steamer_id;
                formData.is_audit = e;
                //请求邀请者列表
                that.$http.post(that.adminApi.api_url + "/steamer/audit", formData, {
                    emulateJSON: true
                }).then(
                    function (res) {
                        that.$message({
                            type: 'success',
                            message: `操作提示: ${ '审核成功' }`
                        });
                        that.$router.go(-1);
                    },
                    function () {
                        // 处理失败的结果
                        that.$message({
                            type: 'error',
                            message: `操作提示: ${ '处理异常' }`
                        });
                    });
            })
        }
    }
}